<?php
/**
 * Created by PhpStorm.
 * User: junyv
 * Date: 2017/4/3
 * Time: 15:25
 */

namespace app\home\controller;


class Tuangou extends Base
{
    public function index(){
        $this->_lists();
        return  $this->fetch();
    }
    public function detail(){
        $id = input('param.id/d',0);
        if($id){
            $where['id'] = $id;
           // $time        = time();
           // $where['begin_time'] = ['lt',$time];
            //$where['end_time']   = ['gt',$time];
            $info = model('house_group')->where($where)->find();
            if(!$info){
                return $this->fetch('public/404');
            }
            $explain = cache('explain');
            $house = model('house')->where(['id'=>$info['house_id'],'status'=>1])->field('city_name,area_name,address,tags_name')->find();
            $this->setSeo($info);
            $this->assign('info',$info);
            $this->assign('house',$house);
            $this->assign('explain',$explain['group']);
        }else{
            return $this->fetch('public/404');
        }
        return $this->fetch();
    }
    private function search(){
        $timeout = input('param.timeout/d',0);
        $time    = time();
        if($timeout == 1){
            $where['end_time'] = ['lt',$time];
        }else{
            $where['end_time']   = ['gt',$time];
            $where['begin_time'] = ['lt',$time];
        }
        $where['city']  = $this->cityInfo['id'];
        $this->assign('timeout',$timeout);
        $this->assign('param',['timeout'=>$timeout]);
        return $where;
    }
    private function _lists(){
        $where = $this->search();
        $lists = model('house_group')->where($where)->field('id,house_id,title,youhui,city,area,begin_time,end_time,price,old_price,img,buy_num')->order('id desc')->paginate(5);
        $this->assign('lists',$lists);
        $this->assign('pages',$lists->render());
    }
}